package com.yike.user.service.impl;

import com.yike.user.entity.AgentCommission;
import com.yike.user.mapper.AgentCommissionMapper;
import com.yike.user.service.AgentCommissionService;
import com.yike.user.param.AgentCommissionPageParam;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yike.common.base.BaseServiceImpl;
import com.yike.common.pagination.Paging;
import com.yike.common.pagination.PageInfo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.transaction.annotation.Transactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 代理商分佣表 服务实现类
 *
 * @author Sakura
 * @since 2024-09-09
 */
@Slf4j
@Service
public class AgentCommissionServiceImpl extends BaseServiceImpl<AgentCommissionMapper, AgentCommission> implements AgentCommissionService {

    @Autowired
    private AgentCommissionMapper agentCommissionMapper;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean saveAgentCommission(AgentCommission agentCommission) throws Exception {
        return super.save(agentCommission);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean updateAgentCommission(AgentCommission agentCommission) throws Exception {
        return super.updateById(agentCommission);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean deleteAgentCommission(Long id) throws Exception {
        return super.removeById(id);
    }

    @Override
    public Paging<AgentCommission> getAgentCommissionPageList(AgentCommissionPageParam agentCommissionPageParam) throws Exception {
        Page<AgentCommission> page = new PageInfo<>(agentCommissionPageParam, OrderItem.desc(getLambdaColumn(AgentCommission::getCreateTime)));
        LambdaQueryWrapper<AgentCommission> wrapper = new LambdaQueryWrapper<>();
        IPage<AgentCommission> iPage = agentCommissionMapper.selectPage(page, wrapper);
        return new Paging<AgentCommission>(iPage);
    }

}
